
#ifndef _VIDEO_DISPLAY_WIDGET_H
#define _VIDEO_DISPLAY_WIDGET_H

#include <math.h>
#include <iostream>


//#include <opencv2/opencv.hpp>
//#include <opencv2/imgproc/imgproc_c.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv/ml.h>
#include <opencv/cxcore.h>
#include <dc1394/dc1394.h>



#include <QtOpenGL/QGLWidget>
#include <QtCore/QTimer>
#include <QtGui>
#include <QKeyEvent>
#include <QFileDialog>
#include <QDebug>
#include <opencvblobslib/blob.h>
#include <opencvblobslib/BlobResult.h>
#include <time.h>

#include <newmat11/newmat.h>
#include "Joystick.h"

using namespace std;
using namespace cv;


class VideoWidget:public QGLWidget {
    Q_OBJECT

public:
    VideoWidget(QWidget *parent = 0, Joystick *joystick=0);
    ~VideoWidget();

    void close();

    // threshold values
    int cvthreshold;
    int cvthresholdMax;
    int blobthreshold;

    int noOfBlobs; // total number of blobs in the scene
    int tipBlob; // index of end-effector blob

    int blob_detect; // status of blob detection

    // start and end times to calculate frame rate
    time_t start, end;
    double fps; // FPS of capture
    int count; // frame counter
    double sec;

    void initAxis(int, int , int, int);


public slots:
    void updateImage();

    void rec(int);

    // slots for threshold variables
    void cvThresholdF(int);
    void cvThresholdMaxF(int);
    void blobThresholdF(int);

signals:


protected:
    void initializeGL();
    void paintGL();



private:

    // variables for x and y axis
    CvPoint y1axis1;     // + y
    CvPoint y2axis1;     // - y
    CvPoint x1axis1;     // + x
    CvPoint x2axis1;     // - x
    CvPoint x1axis2;     //  x + a
    CvPoint x2axis2;     // - x + a
    CvPoint y1axis2;     // y + a
    CvPoint y2axis2;     // - y + a

    CvPoint c1, c2, c3, c4; // circles at corners

    CvScalar color;

    // target point;
    CvPoint target;

    CvCapture *camera;
    IplImage *frame;
    IplImage *cFrame;
    IplImage *gray_image;
    IplImage *blobImage;


    QTimer *refresh_timer;

    // recording state
    int recState;

    // save video filename
    QString videoFileName;
    // video writer
    CvVideoWriter *videoPtr;

    Joystick *tempJoystick;

    // flags
    int calibration_done;


    // object that will contain blobs of input frame
    CBlobResult blobs;
    CBlob *currentBlob;



};


#endif
